<?php
/*
 * IKPHP爱客网 安装程序 @copyright (c) 2012-3000 IKPHP All Rights Reserved @author 小麦
* @Email:ikphp@sina.cn
* @小麦  站内消息模型 2014年8月9日15:35:37
*/
namespace IKPHP\Common\Models;

class MessageBox extends BaseModel
{
    public function getSource()
    {
        return IK."message";
    }	
    /**
     * 发送消息
     * @param  integer $userid   用户ID
     * @param  integer $touserid 对方ID
     * @param  string  $title    标题
     * @param  string  $content  内容
     * @return boolean ture-成功，false-失败
     */
	public function sendMessage($userid, $touserid, $title, $content) {
		if ($touserid && $content) {
			$data = array (
					'userid' => $userid,
					'touserid' => $touserid,
					'title' => $title,
					'content' => $content,
					'isread' => 0,
					'isspam' => 0,
					'isinbox' => 0,
					'isoutbox' => 0,
					'addtime' => time () 
			);
			if (! false == $this->create ( $data )) {
				return true;
			}
		}
		return false;
	}
	//获取用户未读的消息数目
	public static function getUnreadNum($uid){
		if($uid){
			$map = "touserid = '$uid' and isread=0 and isinbox = 0";
			$count = self::count($map);
			if($count>0){
				return $count;
			}
			return 0;
		}
		return 0;
	}
	
}